//--------------------------------------------------------Fig1_histogram.do
// Fig1 Histogram
// --------------------------------------------------------------------------
version 15 // ensure compatibility
clear all // start in a clean state
cls // clear the results window
set more off // show all output, dont wait if screen full
set seed 12345 // see note below
set rmsg on // displays how time to execute command s
cd "C:\Users\wachb\OneDrive - UvA\WInequality\Replicate_Analysis"
capture log close // closes any log file if currently open
log using Fig1_histogram, replace text

/*
use "C:\Users\wachb\OneDrive - UvA\WInequality\ToShare\Individual\Append\MasterIndividuals.dta"
//histogramdata is collapsed over uniqueid, which consists of year(yyyy), dataset(dd), and countrycode (ISO, ccc).  => yyyyddccc
collapse (max) GTQ Rpjst Rpprlmnt Rpntgvmnt Rpplc Rpplprt year dataset t wave, by(uniqueid)
save histogramdata.dta
*/
//
use histogramdata.dta

label var year "Year" 
label var t "Time Interval"
label var GTQ "Social Trust"
label var Rpjst "Trust in Justice System"
label var Rpprlmnt "Trust in Parliament"
label var Rpntgvmnt "Trust in National Government"
label var Rpplc "Trust in Police"
label var Rpplprt "Trust in Political Parties"


foreach var of varlist (GTQ  Rpprlmnt Rpplprt Rpntgvmnt Rpjst Rpplc){ 
	twoway (histogram year if `var' !=. & t==1, start(1995) width(1) freq disc color(gs3)) ///        
    (histogram year if `var' !=. & t==2, start(1995) width(1) freq disc color(gs6)) ///
	(histogram year if `var' !=. & t==3, start(1995) width(1) freq disc color(gs9)), legend(off) ///   
    legend(order(1 "Time interval 1" "(1995-2005)" 2 "Time interval 2" "(2006-2010)" 3 "Time interval 3" "(2011-2018)") rows(1) symxsize(11)) ///
	scheme(plottig) xlabel(1995(4)2018) ylabel(0(25)150) ytitle(`: var label `var'', size(medium)) xtitle("") ///
	name(`var', replace)
	graph close
}
cd "C:\Users\wachb\OneDrive - UvA\WInequality\Replicate_Analysis"
grc1leg2 GTQ Rpjst Rpprlmnt Rpntgvmnt Rpplc Rpplprt, ycommon xcommon scheme(plottig) saving(Fig1_distribution, replace)
graph close